package com.itheima.d8BSDemo;

import java.io.IOException;
import java.io.OutputStream;
import java.io.PrintStream;
import java.net.ServerSocket;
import java.net.Socket;
import java.util.concurrent.*;

/**
 * public ThreadPoolExecutor(int corePoolSize,
 *                               int maximumPoolSize,
 *                               long keepAliveTime,
 *                               TimeUnit unit,
 *                               BlockingQueue<Runnable> workQueue,
 *                               ThreadFactory threadFactory,
 *                               RejectedExecutionHandler handler)
 */
public class BSDemo {
    public static void main(String[] args) throws IOException {
        ServerSocket serverSocket = new ServerSocket(666);
        ExecutorService pool = new ThreadPoolExecutor(3, 5, 8, TimeUnit.SECONDS
                , new ArrayBlockingQueue<>(2)
                , Executors.defaultThreadFactory()
                , new ThreadPoolExecutor.AbortPolicy());



        while (true) {
            Socket socket = serverSocket.accept();
            Runnable myRunnable = new MyRunnable(socket);
            pool.execute(myRunnable);
        }
    }
}
